//
//  BuyCarViewController.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/8/23.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "BuyCarViewController.h"

#import "BuyCarCell.h"
#import "DianPuViewController.h"
#import "WashCarViewController.h"
#import "AddCarViewController.h"
#import "CheXianViewController.h"
#import "ShangHuViewController.h"

#import "AddServiceViewController.h"
#import "AddSUVViewController.h"
#import "SearchViewController.h"
#import "WashMapViewController.h"
#import "ShangHuViewController.h"

#import "WashSearchViewController.h"
@interface BuyCarViewController ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,BMKMapViewDelegate,BMKLocationServiceDelegate,BMKGeoCodeSearchDelegate>{
    UILabel *labLine;
    NSMutableArray *datas;//购车数据
    NSMutableArray *array2;//洗车数据
    NSMutableArray *array3;//上户数据
    UIView *headview;
    
    BMKMapView *mapView;
    BMKLocationService *location;
    BMKGeoCodeSearch *geocodeSearch;
    NSInteger pageNo;//页数
    CGFloat lat;
    CGFloat lng;
    UIButton *mapBtn;//洗车地图
    
    NSString *_thenumberof;
}

@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSMutableDictionary *dic;
@property (nonatomic,strong)NSMutableArray *arrImages;//轮播数据
@property (nonatomic,copy)NSString *area;
@end

@implementation BuyCarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _dic = [NSMutableDictionary dictionary];
    datas = [NSMutableArray array];
    array2 = [NSMutableArray array];
    array3 = [NSMutableArray array];
    _arrImages = [NSMutableArray array];
    
    [_dic setObject:@"aaa" forKey:@"tag"];
    pageNo = 1;
    
    [self loadNav];
    [self loadUI];
    
    [self loadMap];
    [self loadRefresh];
    
}

- (void)loadMap{
    location = [[BMKLocationService alloc] init];
    [location startUserLocationService];
    
    geocodeSearch = [[BMKGeoCodeSearch alloc] init];
    geocodeSearch.delegate = self;
}

-(void)viewWillAppear:(BOOL)animated{
    [mapView viewWillAppear];
    //定位
    location.delegate = self;
}

-(void)viewWillDisappear:(BOOL)animated{
    [mapView viewWillDisappear];
    location.delegate = nil;
}

#pragma -mark BMKLocationServiceDelegate
-(void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation{
    NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
    lat = userLocation.location.coordinate.latitude;
    lng = userLocation.location.coordinate.longitude;
    
    BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init];
    
    reverseGeocodeSearchOption.reverseGeoPoint = userLocation.location.coordinate;
    
    BOOL flag = [geocodeSearch reverseGeoCode:reverseGeocodeSearchOption];
    if(flag){
        NSLog(@"反geo检索发送成功");
        //停止定位
        [location stopUserLocationService];
        
    }else{
        NSLog(@"反geo检索发送失败");
    }
    //停止定位
    [location stopUserLocationService];
}

//反检索
-(void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error{
    
    NSLog(@"%@---%@---%@--%@",result.addressDetail,result.address,result.businessCircle,result.addressDetail.district);
    _area = result.addressDetail.district;
}

- (void)loadNav{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 64)];
    view.backgroundColor = [UIColor whiteColor];
    view.userInteractionEnabled = YES;
    [self.view addSubview:view];
    
    UILabel *lab = [[UILabel alloc] init];
    lab.text = @"购车";
    lab.textColor = [UIColor blackColor];
    lab.font = [UIFont systemFontOfSize:18.0];
    [view addSubview:lab];
    [lab makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(view.centerX);
        make.top.equalTo(34);
    }];
    
    UILabel *line = [[UILabel alloc] init];
    line.backgroundColor = [UIColor lightGrayColor];
    [view addSubview:line];
    [line makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(0);
        make.right.equalTo(0);
        make.bottom.equalTo(view.bottom);
        make.height.equalTo(0.5);
    }];
    
    //
    UIButton *btnSearch = [UIButton buttonWithType:UIButtonTypeCustom];
    btnSearch.frame = CGRectMake(ScreenWidth-40, 24, 40, 40);
    [btnSearch setImage:[UIImage imageNamed:@"搜索-(1)"] forState:UIControlStateNormal];
    [btnSearch addTarget:self action:@selector(clickSearch) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btnSearch];
    
    mapBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    mapBtn.frame = CGRectMake(0, 24, 40, 40);
    [mapBtn setImage:[UIImage imageNamed:@"地图-(1)"] forState:UIControlStateNormal];
    mapBtn.hidden = YES;
    [mapBtn addTarget:self action:@selector(clickMap) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:mapBtn];
    
}

- (void)clickMap{
    WashMapViewController *map = [[WashMapViewController alloc] init];
    [self.navigationController pushViewController:map animated:YES];
}

- (void)clickSearch{
    NSString *tag = [_dic objectForKey:@"tag"];
    NSString *longitude = [NSString stringWithFormat:@"%f",lng];
    NSString *latitude = [NSString stringWithFormat:@"%f",lat];
    if ([tag isEqualToString:@"aaa"]) {
        SearchViewController *search = [[SearchViewController alloc] init];
        search.lat = latitude;
        search.lng = longitude;
        search.area = _area;
        [self.navigationController pushViewController:search animated:YES];
    }else if ([tag isEqualToString:@"sss"]){
        WashSearchViewController *sear = [[WashSearchViewController alloc] init];
        sear.lat = latitude;
        sear.lng = longitude;
        sear.area = _area;
        [self.navigationController pushViewController:sear animated:YES];
    }else{
        WashSearchViewController *sear = [[WashSearchViewController alloc] init];
        sear.lat = latitude;
        sear.lng = longitude;
        sear.area = _area;
        [self.navigationController pushViewController:sear animated:YES];
    }
}

//轮播图
- (void)loadBanner{
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:@"2" forKey:@"positionid"];
    
    NSString *url = [NSString stringWithFormat:@"%@/App/Banner/automobile",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"res:%@",responseObject);
        NSString *error = [NSString stringWithFormat:@"%li",[[responseObject objectForKey:@"error"] integerValue]];
        if ([error integerValue] == 200) {
            NSString *str = [user objectForKey:@"ImageUrl"];
            NSArray *arr = [responseObject objectForKey:@"result"];
            for (NSDictionary *op in arr) {
                NSString *imgUrl = [NSString stringWithFormat:@"%@%@",str,[op objectForKey:@"banner"]];
                [_arrImages addObject:imgUrl];
            }
            
            UIView *v = [WTImageScroll ShowNetWorkImageScrollWithFream:CGRectMake(0, 0, ScreenWidth, 171) andImageArray:_arrImages andBtnClick:^(NSInteger tagValue) {
                
            }];
            self.tableView.tableHeaderView = v;
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
    }];
    
}

- (void)loadUI{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64-49) style:UITableViewStylePlain];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    //去掉分割线
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    //自适应高度
    _tableView.rowHeight = 163.0;
    [self.view addSubview:_tableView];
    [self loadBanner];
}

#pragma -mark UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSString *str = [_dic objectForKey:@"tag"];
    if ([str isEqualToString:@"aaa"]) {
        return datas.count;
    }else if ([str isEqualToString:@"sss"]){
        return array2.count;
    }
    return array3.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *str = [_dic objectForKey:@"tag"];
    if ([str isEqualToString:@"aaa"]) {
        static NSString *cellId = @"Cell1";
        BuyCarCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (!cell) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"BuyCarCell" owner:nil options:nil] lastObject];
        }
        //取消选中效果
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        NSDictionary *dic = datas[indexPath.row];
<<<<<<< .mine
        cell.labPrice1.text = [NSString stringWithFormat:@"%@万",[dic objectForKey:@"guideprice"]];
||||||| .r207
        cell.labPrice1.text = [NSString stringWithFormat:@"%@万",[dic objectForKey:@"sellingprice"]];
=======
>>>>>>> .r244
        
        //指导价
        cell.labPrice1.text = [NSString stringWithFormat:@"%@万",[dic objectForKey:@"guideprice"]];
        //销售价
        cell.labPrice2.text = [NSString stringWithFormat:@"%@万",[dic objectForKey:@"sellingprice"]];
        //姓名
        cell.labName.text = [dic objectForKey:@"name"];
        //商标
        cell.labStyle.text = [dic objectForKey:@"brand"];
<<<<<<< .mine
        cell.labPrice2.text = [NSString stringWithFormat:@"%@万",[dic objectForKey:@"sellingprice"]];
        //
||||||| .r207
        cell.labPrice2.text = [NSString stringWithFormat:@"%@万",[dic objectForKey:@"guideprice"]];
        //
=======
        //距离
>>>>>>> .r244
        NSString *km = [NSString stringWithFormat:@" %.2fkm",[[dic objectForKey:@"km"] floatValue]];
        
        NSString *countcomment = [NSString stringWithFormat:@" %li",[[dic objectForKey:@"countcomment"] integerValue]];
        _thenumberof = [NSString stringWithFormat:@" %li",[[dic objectForKey:@"thenumberof"] integerValue]];
        if ([_thenumberof integerValue] > 10000) {
            [cell.btnCenter setTitle:[NSString stringWithFormat:@"%.1f万",[_thenumberof floatValue]/10000.0] forState:UIControlStateNormal];
        }else{
            [cell.btnCenter setTitle:_thenumberof forState:UIControlStateNormal];
        }
        //
        NSString *imgUrl = [NSString stringWithFormat:@"%@%@",[user objectForKey:@"ImageUrl"],[dic objectForKey:@"carthemephoto"]];
        //星
        NSString *xin = [dic objectForKey:@"star"];
        CGFloat count = [xin floatValue];
        
        StarView *staView = [[StarView alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
        staView.showStar = count * 20;
        [cell.sview addSubview:staView];
        
        [cell.images sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:[UIImage imageNamed:@"timg-(1)"]];
        
        [cell.btnLeft setTitle:km forState:UIControlStateNormal];
        
        [cell.btnRight setTitle:countcomment forState:UIControlStateNormal];
        
        [cell.btnCenter setImage:[UIImage imageNamed:@"浏览"] forState:UIControlStateNormal];
        //cell.btnLeft.userInteractionEnabled = YES;
        
        return cell;
    }else if ([str isEqualToString:@"sss"]){
        static NSString *cellId = @"Cell2";
        BuyCarCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (!cell) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"BuyCarCell" owner:nil options:nil] lastObject];
        }
        
        //取消选中效果
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (array2.count > 0) {
            NSDictionary *dic = array2[indexPath.row];
            
            cell.labName.text = [dic objectForKey:@"name"];
            cell.labStyle.text = [dic objectForKey:@"carname"];
            //门面价格
            cell.labPrice1.text = [NSString stringWithFormat:@"%@元",[dic objectForKey:@"limousineprice"]];
            
            cell.labYDDP.text = @"丢丢价：";
            cell.labPrice2.text = [NSString stringWithFormat:@"%@元",[dic objectForKey:@"limousinediudiuprice"]];
            
            NSString *str = [dic objectForKey:@"figurepic"];
            NSString *imgUrl = [NSString stringWithFormat:@"%@%@",[user objectForKey:@"ImageUrl"],str];
            [cell.images sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:[UIImage imageNamed:@"timg-(1)"]];
            
            NSString *km = [NSString stringWithFormat:@" %.2fkm",[[dic objectForKey:@"km"] floatValue]];
            NSString *order = [NSString stringWithFormat:@" %li",[[dic objectForKey:@"thenumberof"] integerValue]];
            NSString *countcomment = [NSString stringWithFormat:@" %li",[[dic objectForKey:@"countcomment"] integerValue]];
            
            //星
            NSString *xin = [dic objectForKey:@"star"];
            CGFloat count = [xin floatValue];
            
            StarView *staView = [[StarView alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
            staView.showStar = count * 20;
            [cell.sview addSubview:staView];
            
            [cell.btnLeft setTitle:km forState:UIControlStateNormal];
            [cell.btnCenter setTitle:order forState:UIControlStateNormal];
            //[cell.btnCenter setImage:[UIImage imageNamed:@"订单"] forState:UIControlStateNormal];
            [cell.btnRight setTitle:countcomment forState:UIControlStateNormal];
        }
        
        return cell;
    }else{
        static NSString *cellId = @"Cell3";
        BuyCarCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (!cell) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"BuyCarCell" owner:nil options:nil] lastObject];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.labZDJ.hidden = YES;
        cell.labYDDP.hidden = YES;
        cell.labPrice1.hidden = YES;
        cell.labPrice2.hidden = YES;
        cell.blackLine.hidden = YES;
        
        if (array3.count > 0) {
            NSDictionary *dic = array3[indexPath.row];
            cell.labName.text = [dic objectForKey:@"name"];
            cell.labStyle.text = [dic objectForKey:@"profile"];
            NSString *star = [NSString stringWithFormat:@"%li",[[dic objectForKey:@"star"] integerValue]];
            NSInteger index = [star integerValue];
            StarView *starView = [[StarView alloc] initWithFrame:CGRectMake(0, 0, 80, 15)];
            starView.showStar = index * 20;
            [cell.sview addSubview:starView];
            
            NSString *figurepic = [dic objectForKey:@"figurepic"];
            NSArray *str = [figurepic componentsSeparatedByString:@"|"];
            NSString *imgUrl = [NSString stringWithFormat:@"%@%@",[user objectForKey:@"ImageUrl"],str[0]];
            [cell.images sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:[UIImage imageNamed:@"timg-(1)"]];
            
            NSString *km = [NSString stringWithFormat:@" %.2fkm",[[dic objectForKey:@"km"] floatValue]];
            NSString *order = [NSString stringWithFormat:@" %li",[[dic objectForKey:@"order"] integerValue]];
            NSString *count = [NSString stringWithFormat:@" %li",[[dic objectForKey:@"countcomment"] integerValue]];
            [cell.btnLeft setTitle:km forState:UIControlStateNormal];
            [cell.btnCenter setTitle:order forState:UIControlStateNormal];
            [cell.btnRight setTitle:count forState:UIControlStateNormal];
            
        }
        
        return cell;
    }
    
}
//
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    //如果存在就直接返回view
    if (headview)
    {
        return headview;
    }
    headview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 50)];
    headview.backgroundColor = [UIColor whiteColor];
    
    NSArray *array = @[@"购车",@"洗车",@"上户",@"车险"];
    for (NSInteger i=0; i<array.count; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(ScreenWidth/array.count*i, 0, ScreenWidth/array.count, 50);
        [btn setTitle:array[i] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:15.0];
        btn.tag = i;
        [headview addSubview:btn];
        [btn addTarget:self action:@selector(clicks:) forControlEvents:UIControlEventTouchUpInside];
        
        UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth/4*(i+1), 15, 0.5, 20)];
        lab.backgroundColor = COLOR_RGB(226, 227, 219, 1);
        [headview addSubview:lab];
        
    }
    
    labLine = [[UILabel alloc] initWithFrame:CGRectMake((ScreenWidth/4-40)/2, 45, 40, 5)];
    labLine.backgroundColor = [UIColor redColor];
    [headview addSubview:labLine];
    
    return headview;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 50.0;
}

//按钮点击事件
- (void)clicks:(UIButton *)btn{
    if (btn.tag == 0) {
        [_dic setObject:@"aaa" forKey:@"tag"];
        [UIView animateWithDuration:0.3 animations:^{
            labLine.frame = CGRectMake((ScreenWidth/4-40)/2, 45, 40, 5);
        }];
        mapBtn.hidden = YES;
        if (datas.count<=0) {
           [_tableView.mj_header beginRefreshing];
        }else{
            [_tableView reloadData];
        }
        
    }else if (btn.tag == 1){
        [_dic setObject:@"sss" forKey:@"tag"];
        [UIView animateWithDuration:0.3 animations:^{
            labLine.frame = CGRectMake((ScreenWidth/4-40)/2+(ScreenWidth/4), 45, 40, 5);
        }];
        mapBtn.hidden = NO;
        if (array2.count<=0) {
            [_tableView.mj_header beginRefreshing];
        }else{
            [_tableView reloadData];
        }
    }else if (btn.tag == 2){
        [_dic setObject:@"ddd" forKey:@"tag"];
        [UIView animateWithDuration:0.3 animations:^{
            labLine.frame = CGRectMake((ScreenWidth/4-40)/2+(ScreenWidth/4)*2, 45, 40, 5);
        }];
        mapBtn.hidden = YES;
        if (array3.count<=0) {
            [_tableView.mj_header beginRefreshing];
        }else{
            [_tableView reloadData];
        }
        
    }else{
        /*
        [_dic setObject:@"fff" forKey:@"tag"];
        [UIView animateWithDuration:0.3 animations:^{
            labLine.frame = CGRectMake((ScreenWidth/4-40)/2+(ScreenWidth/4)*3, 45, 40, 5);
        }];
        mapBtn.hidden = YES;
        [_tableView reloadData];*/
        
        CheXianViewController *clbx = [[CheXianViewController alloc] init];
        [self.navigationController pushViewController:clbx animated:YES];
    }
    
}
//点击cell事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
<<<<<<< .mine
    BuyCarCell * cell =(BuyCarCell *)[tableView cellForRowAtIndexPath:indexPath];
||||||| .r207
=======
    
>>>>>>> .r244
    NSString *str = [_dic objectForKey:@"tag"];
    NSString *longitude = [NSString stringWithFormat:@"%f",lng];
    NSString *latitude = [NSString stringWithFormat:@"%f",lat];
    
<<<<<<< .mine
    if ([_thenumberof integerValue] > 10000) {
        [cell.btnCenter setTitle:[NSString stringWithFormat:@"%.1f万",[_thenumberof floatValue]/10000.0] forState:UIControlStateNormal];
    }else{
        [cell.btnCenter setTitle:[NSString stringWithFormat:@"%zd",_thenumberof.integerValue +1] forState:UIControlStateNormal];
    }
    
    if ([str isEqualToString:@"aaa"]) {
||||||| .r207
    if ([str isEqualToString:@"aaa"]) {
=======
    if ([str isEqualToString:@"aaa"]) {//购车
>>>>>>> .r244
        //属性传值
        NSDictionary *dic = datas[indexPath.row];
        NSString *carid = [dic objectForKey:@"id"];
        NSString *name = [dic objectForKey:@"name"];
        NSString *place = [dic objectForKey:@"suite"];
        NSString *llcount = [NSString stringWithFormat:@"%li",[[dic objectForKey:@"thenumberof"] integerValue]];
        NSString *start = [NSString stringWithFormat:@"%.2f",[[dic objectForKey:@"star"] floatValue]];
        NSString *km = [NSString stringWithFormat:@"%.2fkm",[[dic objectForKey:@"km"] floatValue]];
        //图片数组
        NSString *figurepic = [dic objectForKey:@"figurepic"];
        NSArray *arr = [figurepic componentsSeparatedByString:@"|"];
        NSMutableArray *images = [NSMutableArray array];
        for (NSString *imgFoot in arr) {
            NSString *imgUrl = [NSString stringWithFormat:@"%@%@",[user objectForKey:@"ImageUrl"],imgFoot];
            [images addObject:imgUrl];
        }
        
        DianPuViewController *det = [[DianPuViewController alloc] init];
        det.CarId = carid;
        det.name = name;
        det.place = place;
        det.count = llcount;
        det.start = start;
        det.arrays = images;
        det.km = km;
        det.lat = latitude;
        det.lng = longitude;
        [self.navigationController pushViewController:det animated:YES];
    }else if ([str isEqualToString:@"sss"]){//洗车
        //属性传值
        NSDictionary *op = array2[indexPath.row];
        NSString *merid = [op objectForKey:@"id"];
        NSString *name2 = [op objectForKey:@"name"];
        NSString *place2 = [op objectForKey:@"suite"];
        NSString *llcount2 = [NSString stringWithFormat:@"%li",[[op objectForKey:@"thenumberof"] integerValue]];
        NSString *start2 = [NSString stringWithFormat:@"%.2f",[[op objectForKey:@"star"] floatValue]];
        NSString *km2 = [NSString stringWithFormat:@"%.2fkm",[[op objectForKey:@"km"] floatValue]];
        //图片数组
        NSString *figurepic = [op objectForKey:@"figurepic"];
        NSArray *arr = [figurepic componentsSeparatedByString:@"|"];
        NSMutableArray *images = [NSMutableArray array];
        for (NSString *imgFoot in arr) {
            NSString *imgUrl = [NSString stringWithFormat:@"%@%@",[user objectForKey:@"ImageUrl"],imgFoot];
            [images addObject:imgUrl];
        }
        
        WashCarViewController *car = [[WashCarViewController alloc] init];
        car.merId = merid;
        car.name = name2;
        car.place = place2;
        car.count = llcount2;
        car.start = start2;
        car.images = images;
        car.km = km2;
        car.lat = latitude;
        car.lng = longitude;
        [self.navigationController pushViewController:car animated:YES];
    }else{//上户
        NSDictionary *op = array3[indexPath.row];
        //图片数组
        NSString *figurepic = [op objectForKey:@"figurepic"];
        NSArray *arr = [figurepic componentsSeparatedByString:@"|"];
        NSMutableArray *images = [NSMutableArray array];
        for (NSString *imgFoot in arr) {
            NSString *imgUrl = [NSString stringWithFormat:@"%@%@",[user objectForKey:@"ImageUrl"],imgFoot];
            [images addObject:imgUrl];
        }
        
        NSString *merid = [NSString stringWithFormat:@"%li",[[op objectForKey:@"id"] integerValue]];
        NSString *name = [op objectForKey:@"name"];
        NSString *det = [op objectForKey:@"profile"];
        NSString *place = [op objectForKey:@"suite"];
        NSString *star = [NSString stringWithFormat:@"%li",[[op objectForKey:@"star"] integerValue]];
        NSString *order = [NSString stringWithFormat:@"%li",[[op objectForKey:@"order"] integerValue]];
        
        ShangHuViewController *shanghu = [[ShangHuViewController alloc] init];
        shanghu.merid = merid;
        shanghu.name = name;
        shanghu.det =det;
        shanghu.place = place;
        shanghu.stats = star;
        shanghu.order = order;
        shanghu.images = images;
        shanghu.lat = latitude;
        shanghu.lng = longitude;
        [self.navigationController pushViewController:shanghu animated:YES];
    }
}
//
- (void)loadRefresh{
    //下拉刷新
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadTag)];
    //
    [self.tableView.mj_header beginRefreshing];
    //根据位置设置半透明
    self.tableView.mj_header.automaticallyChangeAlpha = YES;
    //上拉加载更多
    self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    
}

- (void)loadTag{
    NSString *tag = [_dic objectForKey:@"tag"];
    if ([tag isEqualToString:@"aaa"]) {
        [self loadData];
    }else if ([tag isEqualToString:@"sss"]){
        [self loadData2];
    }else{
        [self loadData3];
    }
    
}

- (void)loadMoreData{
    [_tableView.mj_header endRefreshing];
    pageNo++;
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    NSString *longitude = [NSString stringWithFormat:@"%f",lng];
    NSString *latitude = [NSString stringWithFormat:@"%f",lat];
    [parmas setObject:longitude forKey:@"longitude"];
    [parmas setObject:latitude forKey:@"latitude"];
    [parmas setObject:[NSString stringWithFormat:@"%li",pageNo] forKey:@"p"];
    
    NSString *tag = [_dic objectForKey:@"tag"];
    NSString *url;
    if ([tag isEqualToString:@"aaa"]) {
        url = [NSString stringWithFormat:@"%@/App/CarBuying/index",urlHead];
    }else if ([tag isEqualToString:@"sss"]){
        url = [NSString stringWithFormat:@"%@/App/CarWash/index",urlHead];
    }else{
        url = [NSString stringWithFormat:@"%@/App/Onthedoor/index",urlHead];
    }
    NSLog(@"parmas:%@",parmas);
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"res:%@",responseObject);
        NSArray *arr = [responseObject objectForKey:@"result"];
        NSLog(@"arrcount:%li",arr.count);
        
        if ([tag isEqualToString:@"aaa"] && arr.count > 0) {
            [datas addObjectsFromArray:arr];
//            [_tableView reloadData];
        }else if ([tag isEqualToString:@"sss"] && [arr isKindOfClass:[NSArray class]]){
            [array2 addObjectsFromArray:arr];
//            [_tableView reloadData];
        }else{
            [array3 addObjectsFromArray:arr];
            
        }
        [_tableView reloadData];
        [_tableView.mj_footer endRefreshing];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        [_tableView.mj_footer endRefreshing];
    }];
    
}

//购车店铺列表
- (void)loadData{
    [_tableView.mj_footer endRefreshing];
    pageNo = 1;
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    NSString *longitude = [NSString stringWithFormat:@"%f",lng];
    NSString *latitude = [NSString stringWithFormat:@"%f",lat];
    [parmas setValue:longitude forKey:@"longitude"];
    [parmas setValue:latitude forKey:@"latitude"];
    [parmas setValue:[NSString stringWithFormat:@"%li",pageNo] forKey:@"p"];
    NSLog(@"parmas:%@",parmas);
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *url = [NSString stringWithFormat:@"%@/App/CarBuying/index",urlHead];
    NSLog(@"url:%@",url);
    [manager POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"购车res:%@",responseObject);
        NSArray *arr = [responseObject objectForKey:@"result"];
        NSLog(@"arr%@",arr);
        if ([arr isKindOfClass:[NSArray class]] && arr.count > 0) {
            datas = [arr mutableCopy];
            NSLog(@"datas:%@",datas[0]);
            NSLog(@"购车datascount:%li",datas.count);
            
        }
        [_tableView reloadData];
        [_tableView.mj_header endRefreshing];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [_tableView.mj_header endRefreshing];
    }];
    
}
//洗车店铺列表
- (void)loadData2{
    [_tableView.mj_footer endRefreshing];
    pageNo = 1;
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    NSString *longitude = [NSString stringWithFormat:@"%f",lng];
    NSString *latitude = [NSString stringWithFormat:@"%f",lat];
    [parmas setValue:longitude forKey:@"longitude"];
    [parmas setValue:latitude forKey:@"latitude"];
    [parmas setValue:[NSString stringWithFormat:@"%li",pageNo] forKey:@"p"];
    NSLog(@"parmas:%@",parmas);
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *url = [NSString stringWithFormat:@"%@/App/CarWash/index",urlHead];
    [manager POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {

        NSArray *arr = [responseObject objectForKey:@"result"];
        if (arr.count > 0) {
            array2 = [arr mutableCopy];
            NSLog(@"array2:%@",array2[0]);
            NSLog(@"洗车array:%li",array2.count);
            
        }
        [_tableView reloadData];
        [_tableView.mj_header endRefreshing];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [_tableView.mj_header endRefreshing];
    }];
}
//上户-店铺列表
- (void)loadData3{
    [_tableView.mj_footer endRefreshing];
    pageNo = 1;
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    NSString *longitude = [NSString stringWithFormat:@"%f",lng];
    NSString *latitude = [NSString stringWithFormat:@"%f",lat];
    [parmas setValue:longitude forKey:@"longitude"];
    [parmas setValue:latitude forKey:@"latitude"];
    [parmas setValue:[NSString stringWithFormat:@"%li",pageNo] forKey:@"p"];
    
    NSString *url = [NSString stringWithFormat:@"%@/App/Onthedoor/index",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"上户res:%@",responseObject);
        NSString *error = [NSString stringWithFormat:@"%li",[[responseObject objectForKey:@"error"] integerValue]];
        if ([error integerValue] == 200) {
            array3 = [responseObject objectForKey:@"result"];
            
        }
        [_tableView reloadData];
        [_tableView.mj_header endRefreshing];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [_tableView.mj_header endRefreshing];
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
